package org.agridata.akvisualization.controller.pestilence;

import com.alibaba.excel.EasyExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.agridata.akvisualization.doMain.entity.Brucellosis;
import org.agridata.akvisualization.doMain.entity.Pestilence;
import org.agridata.akvisualization.result.Result;
import org.agridata.akvisualization.service.DiseaseSurveillanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/pestilence")
@Api(tags = "疫病监测情况")
public class DiseaseSurveillanceController {

    @Autowired
    private DiseaseSurveillanceService surveillanceService;

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("疫病监测导入")
    @PostMapping("/diseaseImport")
    public Result diseaseImport(@RequestPart("file") MultipartFile file, String dates,String user){
        try {
            List<Pestilence> memberList = EasyExcel.read(file.getInputStream())
                    .head(Pestilence.class)
                    .sheet()
                    .doReadSync();
            return surveillanceService.importDiseaseSurveillance(memberList,dates,user);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.fail("出现异常");
        }

    }

    @ApiOperation("疫病监测列表")
    @PostMapping("/diseaseList")
    public Result diseaseList(String pestilence ,Long pageNo,Long pageSize){
        return surveillanceService.diseaseListPage(pestilence,pageNo,pageSize);
    }

    @ApiOperation("疫病柱状图")
    @PostMapping("/barChart")
    public Result barChart(Integer type){
        return surveillanceService.barChartByMonth(type);
    }

    @ApiOperation("布病监测导入")
    @PostMapping("/brucellosisImport")
    public Result brucellosisImport (@RequestPart("file") MultipartFile file, String category,String user){
        try {
            List<Brucellosis> memberList = EasyExcel.read(file.getInputStream())
                    .head(Brucellosis.class)
                    .sheet()
                    .doReadSync();
            return surveillanceService.importBrucellosis(memberList,category,user);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.fail("出现异常");
        }
    }

    @ApiOperation("布病监测列表")
    @PostMapping("brucellosisList")
    public Result brucellosisList (){
        return surveillanceService.brucellosisList();
    }

    @ApiOperation("疫病监测上传记录")
    @PostMapping("/diseaseListJiLu")
    public Result diseaseListJiLu(String date,Long pageNo,Long pageSize){
        return surveillanceService.diseaseListJiLu(date,pageNo,pageSize);
    }

    @ApiOperation("布病监测上传记录")
    @PostMapping("/brucellosisJiLu")
    public Result brucellosisJiLu(String date,Long pageNo,Long pageSize){
        return surveillanceService.brucellosisJiLu(date,pageNo,pageSize);
    }



    @ApiOperation("疫病监测可视化首页")
    @PostMapping("homePage")
    public Result homePage (){
        return surveillanceService.homePageByNewDate();
    }

}
